import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 周斌
 * Date: 2023-12-25
 * Time: 21:35
 */
public class Test {
    //时间复杂度太高 时间复杂度:k*n
    public static void main1(String[] args) {
        int[] aray = {-1,-100,3,99};
        int k = 2;
        while(k!=0) {
            int cor = aray.length - 1;
            int ret = aray[cor];//存储一个数组最后的数
            while(cor!=0) {
                aray[cor] = aray[cor-1];
                cor--;
            }
            aray[cor] = ret;
            k--;
        }
        //打印这个数组
        System.out.println(Arrays.toString(aray));
    }

    //翻转数组 时间复杂度为O(n),空间复杂度为O(1)
    public static void reverse(int[] aray,int start,int end) {
        while(start<end) {
            int tmp = aray[start];
            aray[start++] = aray[end];
            aray[end--] = tmp;
        }
    }
    public static void main(String[] args) {
        int[] aray ={1,2,3,4,5,6,7};
        int k=3;
        reverse(aray,0,aray.length-1);//全部翻转
        reverse(aray,0,k-1);//翻转前k个
        reverse(aray,k,aray.length-1);//翻转剩余的
        System.out.println(Arrays.toString(aray));
    }
}
